package kr.hkit.powerjava.chther25.chat;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

public class QuizClient {
	public static void main(String[] args) throws IOException {
		Socket quizeSocket =null;
		PrintWriter out =null;
		BufferedReader in =null;
		BufferedReader user =null;
		
		String servermsg;
		String sendmsg;
		
		try {
			quizeSocket = new Socket("localhost",5555);
			out = new PrintWriter(quizeSocket.getOutputStream(),true);
			in = new BufferedReader(new InputStreamReader(quizeSocket.getInputStream()));
			user = new BufferedReader(new InputStreamReader(System.in));
		} catch (UnknownHostException e) {
			System.err.println("localhost 에 접근할수없어요");
			System.exit(-1);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		while ((servermsg = in.readLine()) != null) {
			System.out.println("서버:"+servermsg);
			if(servermsg.equalsIgnoreCase("quit")){
				break;
			}
			sendmsg = user.readLine();
			if(sendmsg != null){
				System.out.println("클라이업트:"+sendmsg);
				out.println(sendmsg);
			}
		}
		user.close();
		in.close();
		out.close();
		quizeSocket.close();
	}
}	
